package com.msh.automatic.android.control.script.util

import cn.hutool.http.HttpGlobalConfig
import cn.hutool.http.HttpRequest
import cn.hutool.http.HttpUtil
import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONObject
import com.msh.automatic.android.control.script.task.TaskManager

object BaseApi {
    val BASE_URL="https://automatic-android-api.jobeyond.cn"

    fun post(api:String,params:Map<String, Any>):Triple<String,String,JSONObject?>{
        val request = HttpRequest.post("$BASE_URL$api")
            .timeout(HttpGlobalConfig.getTimeout())
            .body(JSON.toJSONString(params))

        // 如果 token 不为空，添加 header
        request.header("x-msh-token", TaskManager.token)

        val res = request.execute().body()
        val json = JSONObject.parseObject(res)
        return Triple(json.getString("code")!!,json.getString("message")!!,json.getJSONObject("body"))
    }
}